package com.right.health.app.ui.registered.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;

/*
 * Created by hopeliao on 2019-09-24
 *
 */
public class DepartmentLeftAdapter extends BaseAbsAdapter<String> {

    private int mSelectedIndex;

    public void setSelectIndex(int index) {
        this.mSelectedIndex = index;
    }

    public DepartmentLeftAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.choose_department_left_item, null);
            viewHolder = new ViewHolder();
            viewHolder.contentImage = (ImageView) convertView.findViewById(R.id.iv_content);
            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.rootView = convertView.findViewById(R.id.root_view);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.nameTv.setSelected(mSelectedIndex == position);
        viewHolder.rootView.setBackgroundColor(
                mSelectedIndex == position ?
                        mContext.getResources().getColor(R.color.white) :
                        mContext.getResources().getColor(R.color.common_gray_color));
        return convertView;
    }

    private class ViewHolder {
        private ImageView contentImage;
        private TextView nameTv;
        private View rootView;
    }
}
